/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SetupFlightCtrBox.java
 *
 * Created on Jul 30, 2009, 2:07:18 AM
 */

package Falcon;

import org.jdesktop.application.Action;

/**
 *
 * @author Joe
 */
public class SetupFlightCtrBox extends javax.swing.JDialog {

    /** Creates new form TestStrBox */
    public SetupFlightCtrBox(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        settingsHandler = SettingsHandler.getInstance();
        settingsHandler.loadSettings();
        setDefaults();
        fillValues();
    }


    private void setDefaults(){
        fcLatVal = settingsHandler.get("FlightCtrSetup_fcLatVal");
        fcLonVal = settingsHandler.get("FlightCtrSetup_fcLonVal");
        fcAltVal = settingsHandler.get("FlightCtrSetup_fcAltVal");
    }
    private void fillValues(){
        fcLatText.setText(fcLatVal);
        fcLonText.setText(fcLonVal);
        fcAltText.setText(fcAltVal);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fcLatText = new javax.swing.JTextField();
        fcLatLabel = new javax.swing.JLabel();
        cancelButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        fcLonLabel = new javax.swing.JLabel();
        fcLonText = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        fcAltLabel = new javax.swing.JLabel();
        fcAltText = new javax.swing.JTextField();
        okButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(Falcon.FalconMainApp.class).getContext().getResourceMap(SetupFlightCtrBox.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        fcLatText.setText(resourceMap.getString("fcLatText.text")); // NOI18N
        fcLatText.setName("fcLatText"); // NOI18N

        fcLatLabel.setText(resourceMap.getString("fcLatLabel.text")); // NOI18N
        fcLatLabel.setName("fcLatLabel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(Falcon.FalconMainApp.class).getContext().getActionMap(SetupFlightCtrBox.class, this);
        cancelButton.setAction(actionMap.get("cancelButton")); // NOI18N
        cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
        cancelButton.setName("cancelButton"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        fcLonLabel.setText(resourceMap.getString("fcLonLabel.text")); // NOI18N
        fcLonLabel.setName("fcLonLabel"); // NOI18N

        fcLonText.setText(resourceMap.getString("fcLonText.text")); // NOI18N
        fcLonText.setName("fcLonText"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        fcAltLabel.setText(resourceMap.getString("fcAltLabel.text")); // NOI18N
        fcAltLabel.setName("fcAltLabel"); // NOI18N

        fcAltText.setText(resourceMap.getString("fcAltText.text")); // NOI18N
        fcAltText.setName("fcAltText"); // NOI18N

        okButton.setAction(actionMap.get("okButton")); // NOI18N
        okButton.setText(resourceMap.getString("okButton.text")); // NOI18N
        okButton.setName("okButton"); // NOI18N

        jSeparator3.setName("jSeparator3"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(fcLatLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fcLatText, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(okButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(fcLonLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fcLonText, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(fcAltLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fcAltText, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))
                    .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fcLatLabel)
                    .addComponent(fcLatText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fcLonText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fcLonLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fcAltLabel)
                    .addComponent(fcAltText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(okButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void okButton() {
        fcLatVal = fcLatText.getText();
        fcLonVal = fcLonText.getText();
        fcAltVal = fcAltText.getText();
        settingsHandler.put("FlightCtrSetup_fcLatVal", fcLatText.getText());
        settingsHandler.put("FlightCtrSetup_fcLonVal", fcLonText.getText());
        settingsHandler.put("FlightCtrSetup_fcAltVal", fcAltText.getText());
        settingsHandler.saveSettings();
        this.setVisible(false);
    }

    @Action
    public void cancelButton() {
        fcLatText.setText(fcLatVal);
        fcLonText.setText(fcLonVal);
        fcAltText.setText(fcAltVal);
        this.setVisible(false);
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel fcAltLabel;
    private javax.swing.JTextField fcAltText;
    private javax.swing.JLabel fcLatLabel;
    private javax.swing.JTextField fcLatText;
    private javax.swing.JLabel fcLonLabel;
    private javax.swing.JTextField fcLonText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables


    private String fcLatVal;
    private String fcLonVal;
    private String fcAltVal;
    SettingsHandler settingsHandler;

    public Position getFcPos(){
        return new Position(
                Double.parseDouble(fcLatVal),
                Double.parseDouble(fcLonVal),
                Double.parseDouble(fcAltVal));
    }
}
